package com.miao.manage.web.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.miao.entity.TbItemDesc;
import com.miao.service.TbItemDescService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping("/api/itemDesc")
@Controller
public class ApiItemDescController {

    @Autowired
    private TbItemDescService tbItemDescService;

    @RequestMapping(value = "{itemId}",method = RequestMethod.GET)
    public ResponseEntity<TbItemDesc> queryItemById(@PathVariable("itemId")String itemId){
        try{
            EntityWrapper wrapper = new EntityWrapper();
            wrapper.setSqlSelect("item_id,item_desc,created,updated");
            wrapper.where("item_id={0}",itemId);
            TbItemDesc tbItemDesc = tbItemDescService.selectOne(wrapper);
            if(null==tbItemDesc){
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            return ResponseEntity.ok(tbItemDesc);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
